package com.woniuxy.main.dynamic_lzq.test;

import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;
public class MapDistance {
	
	public static double findDistance(double userLongitude,double userLatitude,double targetLongitude,double targetLatitude){
		GlobalCoordinates source = new GlobalCoordinates(userLatitude, userLongitude);
        GlobalCoordinates target = new GlobalCoordinates(targetLatitude, targetLongitude);

        double meter = getDistanceMeter(source, target, Ellipsoid.Sphere);
        meter =  (double)Math.round(meter * 100) / 100;
       // System.out.println("Sphere坐标系计算结果："+meter + "米");
		return meter;
		
	}
	
	 public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo, Ellipsoid ellipsoid)
	    {
	        //创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
	        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(ellipsoid, gpsFrom, gpsTo);

	        return geoCurve.getEllipsoidalDistance();
	    }
}
